<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>员工列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        header {
            background-color: #333;
            color: white;
            padding: 15px 0;
            margin-bottom: 30px;
        }
        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        nav a {
            color: white;
            text-decoration: none;
            margin-left: 20px;
        }
        nav a:hover {
            text-decoration: underline;
        }
        main {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h2 {
            color: #333;
            margin-bottom: 20px;
            border-bottom: 2px solid #4CAF50;
            padding-bottom: 10px;
        }
        .search-form {
            background-color: #f9f9f9;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 20px;
        }
        .form-row {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
        }
        .form-group {
            flex: 1;
            min-width: 150px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: bold;
        }
        .form-group input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .btn-search {
            padding: 8px 16px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-top: 20px;
        }
        .employee-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        .employee-table th, .employee-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        .employee-table th {
            background-color: #f2f2f2;
            color: #333;
            font-weight: bold;
        }
        .employee-table tr:hover {
            background-color: #f9f9f9;
        }
        .btn {
            padding: 6px 12px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            font-size: 14px;
        }
        .btn-view {
            background-color: #2196F3;
            color: white;
        }
        .btn-edit {
            background-color: #ff9800;
            color: white;
        }
        .btn-delete {
            background-color: #f44336;
            color: white;
        }
        .btn-add {
            background-color: #4CAF50;
            color: white;
            padding: 10px 16px;
            margin-bottom: 20px;
            display: inline-block;
        }
        .pagination {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }
        .pagination a {
            color: #4CAF50;
            padding: 8px 16px;
            text-decoration: none;
            border: 1px solid #ddd;
            margin: 0 4px;
            border-radius: 4px;
        }
        .pagination a.active {
            background-color: #4CAF50;
            color: white;
            border: 1px solid #4CAF50;
        }
        .pagination a:hover:not(.active) {
            background-color: #ddd;
        }
    </style>
</head>
<body>
<header>
    <div class="header-content">
        <h1>员工信息管理系统</h1>
        <nav>
            <a href="/dashboard">首页</a>
            <a href="/employee/add">添加员工</a>
            <a href="/logout">退出登录</a>
        </nav>
    </div>
</header>

<div class="container">
    <main>
        <h2>员工列表</h2>

        <a href="/employee/add" class="btn btn-add">添加员工</a>

        <!-- 搜索表单 -->
        <form th:action="@{/employee/search}" method="post" class="search-form">
            <div class="form-row">
                <div class="form-group">
                    <label>姓名</label>
                    <input type="text" name="name" th:value="${queryDTO != null ? queryDTO.name : ''}" placeholder="请输入姓名">
                </div>
                <div class="form-group">
                    <label>部门</label>
                    <input type="text" name="department" th:value="${queryDTO != null ? queryDTO.department : ''}" placeholder="请输入部门">
                </div>
                <div class="form-group">
                    <label>职位</label>
                    <input type="text" name="position" th:value="${queryDTO != null ? queryDTO.position : ''}" placeholder="请输入职位">
                </div>
                <div class="form-group">
                    <label>最低工资</label>
                    <input type="number" name="minSalary" th:value="${queryDTO != null ? queryDTO.minSalary : ''}" placeholder="最低工资">
                </div>
                <div class="form-group">
                    <label>最高工资</label>
                    <input type="number" name="maxSalary" th:value="${queryDTO != null ? queryDTO.maxSalary : ''}" placeholder="最高工资">
                </div>
                <div class="form-group">
                    <button type="submit" class="btn-search">搜索</button>
                </div>
            </div>
        </form>

        <!-- 员工列表表格 -->
        <table class="employee-table">
            <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>部门</th>
                <th>职位</th>
                <th>工资</th>
                <th>邮箱</th>
                <th>电话</th>
                <th>入职日期</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="employee : ${pageResult != null ? pageResult.records : employees}">
                <td th:text="${employee.id}"></td>
                <td th:text="${employee.name}"></td>
                <td th:text="${employee.department}"></td>
                <td th:text="${employee.position}"></td>
                <td th:text="${employee.salary}"></td>
                <td th:text="${employee.email}"></td>
                <td th:text="${employee.phone}"></td>
                <td th:text="${#dates.format(employee.hireDate, 'yyyy-MM-dd')}"></td>
                <td>
                    <a th:href="@{/employee/view/{id}(id=${employee.id})}" class="btn btn-view">查看</a>
                    <a th:href="@{/employee/edit/{id}(id=${employee.id})}" class="btn btn-edit">编辑</a>
                    <a th:href="@{/employee/delete/{id}(id=${employee.id})}" class="btn btn-delete" onclick="return confirm('确定要删除吗？')">删除</a>
                </td>
            </tr>
            <tr th:if="${(pageResult != null and pageResult.records.isEmpty()) or (employees != null and employees.isEmpty())}">
                <td colspan="9" style="text-align: center;">暂无员工数据</td>
            </tr>
            </tbody>
        </table>

        <!-- 分页 -->
        <div th:if="${pageResult != null}" class="pagination">
            <a th:href="@{/employee/search(pageNum=1, name=${queryDTO.name}, department=${queryDTO.department}, position=${queryDTO.position}, minSalary=${queryDTO.minSalary}, maxSalary=${queryDTO.maxSalary})}" th:classappend="${pageResult.pageNum == 1 ? 'disabled' : ''}">首页</a>
            <a th:href="@{/employee/search(pageNum=${pageResult.pageNum - 1}, name=${queryDTO.name}, department=${queryDTO.department}, position=${queryDTO.position}, minSalary=${queryDTO.minSalary}, maxSalary=${queryDTO.maxSalary})}" th:classappend="${pageResult.pageNum == 1 ? 'disabled' : ''}">上一页</a>

            <a th:each="i : ${#numbers.sequence(1, pageResult.pages)}"
               th:href="@{/employee/search(pageNum=${i}, name=${queryDTO.name}, department=${queryDTO.department}, position=${queryDTO.position}, minSalary=${queryDTO.minSalary}, maxSalary=${queryDTO.maxSalary})}"
               th:text="${i}"
               th:classappend="${pageResult.pageNum == i ? 'active' : ''}"></a>

            <a th:href="@{/employee/search(pageNum=${pageResult.pageNum + 1}, name=${queryDTO.name}, department=${queryDTO.department}, position=${queryDTO.position}, minSalary=${queryDTO.minSalary}, maxSalary=${queryDTO.maxSalary})}" th:classappend="${pageResult.pageNum == pageResult.pages ? 'disabled' : ''}">下一页</a>
            <a th:href="@{/employee/search(pageNum=${pageResult.pages}, name=${queryDTO.name}, department=${queryDTO.department}, position=${queryDTO.position}, minSalary=${queryDTO.minSalary}, maxSalary=${queryDTO.maxSalary})}" th:classappend="${pageResult.pageNum == pageResult.pages ? 'disabled' : ''}">末页</a>
        </div>
    </main>
</div>
</body>
</html>